package 华为.text08_合并表记录;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //读取行数 ;  nextInt() 之后,  nextLine() 会失效.
        int row = scanner.nextInt();
        String s2 = scanner.nextLine(); // 这就是解决方法
        TreeSet<Integer> set = new TreeSet<>();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < row; i++) {
            String s = scanner.nextLine();
            String[] strings = s.split(" ");
            int key = Integer.parseInt(strings[0]);
            int value = Integer.parseInt(strings[1]);
            Integer mapvalue = map.get(key);
            if (mapvalue==null){
                map.put(key,value);
                set.add(key);
            }else {
                mapvalue = mapvalue + value;
                map.put(key, mapvalue);
                set.add(key);
            }

        }

        for (Integer item : set) {
            System.out.println(item+" "+map.get(item));
        }


    }
}
